<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="姓名" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.student_name }}</span>
        </template>
      </el-table-column>

      <el-table-column label="教师" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.teacher_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="评阅教师" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{
            scope.row.lookteacher_name
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">
            分配
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 弹出框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <!-- 内容区域 -->
      <el-table :data="tableData_1" style="width: 100%">
        <el-table-column label="教师" width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.teacher_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="choose(scope.row)"> 选择 </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 按钮 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">
          确 定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  created() {
    this.pass_topic();
  },
  data() {
    return {
      n: "",
      dialogVisible: false,
      tableData: [],
      tableData_1: [],
    };
  },
  methods: {
    // 获取通过了开题答辩的学生
    pass_topic() {
      this.$http
        .get("http://127.0.0.1:8080/minAdmin/choose_topic")
        .then((res) => {
          console.log(res);
          this.tableData = res.data.data;
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },

    // 操作按钮
    handleEdit(row) {
      this.dialogVisible = true;
      this.disabled = true;
      this.n = row;
      this.$http
        .get("http://127.0.0.1:8080/minAdmin/get_collageteacher")
        .then((res) => {
          res.data.data.forEach((val, index) => {
            if (val.teacher_name == this.n.teacher_name) {
              res.data.data.splice(index, 1);
            }
          });
          this.tableData_1 = res.data.data;
          //   console.log(this.tableData_1);
        });
    },

    // 选择评阅教师
    choose(row) {
      //   console.log(row);
      this.dialogVisible = false;
      const m = { ...this.n, ...row };
      //   console.log(m);
      this.$http
        .post(
          "http://127.0.0.1:8080/minAdmin/insert_teacher",
          this.$qs.stringify(m)
        )
        .then((res) => {
          this.$message.success(res.data.message);
          this.pass_topic();
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
  },
};
</script>
<style lang="less" scoped>
</style>
